package com.ldc.wandroid.adapter;

import android.widget.CheckBox;

import androidx.annotation.NonNull;

import com.ldc.common.common.CommonRecyclerView;
import com.ldc.common.common.CommonRecyclerViewHolder;
import com.ldc.common.common.CommonViewClick;
import com.ldc.common.utils.TimeUtils;
import com.ldc.wandroid.R;
import com.ldc.wandroid.model.WeChatNumberHistoryModel;

import java.util.Date;

public class WeChatNumberHistoryAdapter extends CommonRecyclerView<WeChatNumberHistoryModel.DatasBean> {
    private CommonViewClick<WeChatNumberHistoryModel.DatasBean> commonViewClick;

    public void setCommonViewClick(CommonViewClick<WeChatNumberHistoryModel.DatasBean> commonViewClick) {
        this.commonViewClick = commonViewClick;
    }

    public WeChatNumberHistoryAdapter() {
        super(R.layout.layout_item_wechat_number_history);
    }


    @Override
    protected void convert2Data(@NonNull CommonRecyclerViewHolder holder, WeChatNumberHistoryModel.DatasBean dt, int position) {

        holder
                .setText(R.id.tv_title, String.format("%s•%s", dt.getSuperChapterName(), dt.getChapterName()));
        holder.setText(R.id.tv_context, String.format("%s", dt.getTitle()));
        holder.setText(R.id.tv_author, String.format("%s", dt.getShareUser()));
        holder.setText(R.id.tv_time, String.format("%s", TimeUtils.date2String(new Date(dt.getPublishTime()), "yyyy/MM/dd")));
        ((CheckBox) holder.findViewById(R.id.ck_collect)).setChecked(dt.isCollect());
        holder.itemView.setOnClickListener(v -> {
            if (commonViewClick != null) {
                commonViewClick.onRow(dt);
            }
        });
    }
}
